import { AppBaseEntity } from 'src/shared/database/baseEntity';
import { Column, Entity } from 'typeorm';

export enum OrderStatus {
  // 待支付
  PENDING = 'pending',
  // 已完成
  COMPLETED = 'completed',
  // 已取消
  CANCELLED = 'cancelled',
}

@Entity({
  name: 'orders',
  comment: '订单表',
})
export class Order extends AppBaseEntity {
  @Column({
    comment: '店铺id',
    name: 'store_id',
  })
  storeId: number;

  @Column({
    comment: '用户id',
    name: 'user_id',
  })
  userId: number;

  @Column({
    comment: '订单状态',
    name: 'status',
    type: 'enum',
    enum: OrderStatus,
    default: OrderStatus.PENDING,
  })
  status: OrderStatus;

  @Column({
    comment: '订单总价',
    name: 'total_price',
    type: 'decimal',
    precision: 10,
    scale: 2,
  })
  totalPrice: number;

  @Column({
    comment: '订单项',
    name: 'items',
    type: 'simple-array',
  })
  items: number[];

  @Column({
    comment: '地址id',
    name: 'address_id',
  })
  addressId: number;
}
